provider "alicloud" {
  region                = local.region
}

terraform {
  required_version      = "~> 0.12.0"  
  backend "oss" {
    bucket              = "deeproute-terraform-resources"
    key                 = "stag/services/iac-module-example"
    tablestore_endpoint = "https://terraform-status.cn-shenzhen.ots.aliyuncs.com"
    tablestore_table    = "terraform_statelock_table"    
    region              = "cn-shenzhen"
  }
}

module "random" {
  # source                = "../../../modules/alicloud/random-vswitch"
  source                = "git@code.deeproute.ai:deeproute-org/cloud/cloud/k8s-deployment/ops-terraform.git//alicloud/random-vswitch?ref=module.v1.0.3"
  vswitch_id            = ["vsw-wz9l2fpxwbmbnpfclplsv", "vsw-wz9dmjf3cwwiznco6fuwf"]
}

variable "vpc" {
  default               = "vpc-wz9nh1bbw1cbmdnknw5g7"
}

module "sg" {
  # source                = "../../../modules/alicloud/sg"
  source                = "git@code.deeproute.ai:deeproute-org/cloud/cloud/k8s-deployment/ops-terraform.git//alicloud/sg?ref=module.v1.0.3"
  sg_name               = local.fullname
  vpc_id                = var.vpc
  inbound_rules         = {
    "0" = ["0.0.0.0/0", "22/22", "tcp"]
    # "1" = ["0.0.0.0/0", "80/80", "tcp"]
    # "2" = ["0.0.0.0/0", "443/443", "tcp"]
  }
}

module "ecs_iac-example" {
  # source                       = "../../../modules/alicloud/ecs"
  source                       = "git@code.deeproute.ai:deeproute-org/cloud/cloud/k8s-deployment/ops-terraform.git//alicloud/ecs?ref=module.v1.0.3"
  number_of_instances          = "1"
  ecs_name                     = "stg-iac-example"
  ecs_vswitch_id               = module.random.vswitch_id[0]
  ecs_sg_id                    = [module.sg.sg_id]
  ecs_key_name                 = "devops-key"
  ecs_instance_type            = "ecs.c5.large" // "2h4g"   
  ecs_disk_type                = "cloud_essd"         
  ecs_disk_size                = "80"
  ecs_image                    = "ubuntu_18_04_x64_20G_alibase_20210623.vhd"  //自定义镜像
  ecs_max_bandwidth_out        = "10"
  ecs_internet_billing_type    = "PayByTraffic"    #带宽付费类型[按使用流量付费PayByTraffic、固定带宽付费PayByBandwidth]
  ecs_instance_billing_type    = "PostPaid"        #ecs付费类型[按量付费PostPaid、包年包月PrePaid]
  prepaid_settings             = {
    "period"             = "1"
    "period_unit"        = "Month"
    "renewal_status"     = "AutoRenewal" //自动续订                                                                                                                                                                                                                                                                                                                                                                                                                                         
    "auto_renew_period"  = "1"
    "include_data_disks" = "true"
  }
  spot_strategy                = "NoSpot"  #竞价型实例的价格阈值[NoSpot、SpotWithPriceLimit、SpotAsPriceGo]
  role_name                    = "stg-infrastructure-role"
  tags                         = local.tags
  userdata_TERRAFORM_OSSBUCKET = "deeproute-terraform-resources"
  userdata_VAR_PLAYBOOKS       = [
    "playbooks/common/load-devops-keys.yml",
  ]  
}